import instance from "./axios";

export const getJob = async (_id) => {
    return instance.get('/postlist', { params: { _id } })
}

export const getJobList = async (postName) => {
    return instance.get('/plist', { params: { postName } })
}
//获取手机验证码
export const getRightCode = async (phone) => {
    //获取手机号并向后端发送请求验证码
    let res = await instance.post(`/getCode/${phone}`)
    return res.data
}
//注册
export const register = async (userName, password, email, phone) => {
    return (await instance.post('/register', { userName, password, email, phone })).data
}
//登录
export const login = async (email, password) => {
    return (await instance.post('/login', { email, password })).data
}
//手机号登入
export const Phonelogin = async (phone) => {
    return (await instance.post('/Phonelogin', { phone })).data
}
//获取邮箱验证码
export const getEmailCode = async (email) => {
    return (await instance.post('/email', { email })).data
}
//邮箱修改密码
export const emailReset = async (email, password) => {
    return (await instance.put('/emailReset', { email, password })).data
}
//手机号修改密码
export const phoneReset = async (phone, password) => {
    return (await instance.put('/phoneReset', { phone, password })).data
}


//获取用户信息
export const getUserInfo = async (id) => {
    try {
        if (id) {
            const res = await instance.get(`/userInfo/${id}`)
            return res.data
        }
    } catch (err) {
        console.log(err);
    }
}

//获取会话列表（聊天室）
export const getConversation = async (id) => {
    try {
        const res = await instance.get(`/conv/${id}`)
        return res.data
    } catch (err) {
        console.log(err);
    }
}

// 获取用户的对话信息
export const getMessage = async (convId) => {
    try {
        const res = await instance.get(`/mess/${convId}`)
        return res.data
    } catch (err) {
        console.log(err);
    }
}


// 发送消息
export const sendeMessasge = async (data) => {
    try {
        const res = await instance.post('/mess', data)
        return res.data
    } catch (err) {
        console.log(err);
    }
}
